<?php

namespace App\Console\Commands;

use App\Repositories\Contracts\PlatformInterface;
use App\Repositories\Contracts\PolicyInterface;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;

class HbGjPolicyUploadCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'hbgj:policyUpload';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'hbgj:policy';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle(PlatformInterface $platformInterface,PolicyInterface $policyInterface)
    {
        //

        while (true) {

            try {

                $flightLineData = Redis::rpop('cz_share_flight');

                if ($flightLineData) {
                    $flightLineData = json_decode($flightLineData,true);

                    //获取所有规则
                    $policy = $policyInterface->get(['status'=>1]);

                    //上传政策
                    $res = $platformInterface->uploadPolicy($flightLineData,$policy);
                }
            } catch (\Exception $exception) {


                var_dump($exception->getMessage());
            }

        }
    }
}
